package com.xiong.wuliao.util;

import com.xiong.wuliao.entity.ZhuanTi;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/11/7.
 */
public class ZhuanTiJSON {

    public static List<ZhuanTi> saveZhuanTiData(String s) {
        List<ZhuanTi> zhuanTiList = new ArrayList<>();
        JSONObject jsonObject = null;
        try {
            jsonObject = new JSONObject(s.trim());
            JSONObject object = jsonObject.optJSONObject("data");
            JSONArray array = object.optJSONArray("collections");

            for (int index = 0; index < array.length(); index++) {
                ZhuanTi zhuanTi = new ZhuanTi();
                JSONObject obj = array.optJSONObject(index);

                zhuanTi.setBanner_image_url(obj.optString("banner_image_url"));
                zhuanTi.setCover_image_url(obj.optString("cover_image_url"));
                zhuanTi.setCreated_at(obj.optString("created_at"));
                zhuanTi.setId(obj.optString("id"));
                zhuanTi.setPosts_count(obj.optString("posts_count"));
                zhuanTi.setSubtitle(obj.optString("subtitle"));
                zhuanTi.setTitle(obj.optString("title"));

                zhuanTiList.add(zhuanTi);

            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return zhuanTiList;
    }

}
